package kr.or.javacafe.manage.bo;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import kr.or.javacafe.manage.domain.Information;
import kr.or.javacafe.manage.dao.*;

@Service
public class ManageBOImpl implements ManageBO{

	@Autowired
	private ManageDAO manageDAO;
	

	@Override
	@Transactional (readOnly=true)
	public Information getWelcome() {
		Information param = new Information();
		param.setId("welcome");
		
		return manageDAO.selectInfomation(param);
	}
	
	
	@Override
	@Transactional
	public void editWelcome(Information param) {
		String strId;
		Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		strId = ((UserDetails)principal).getUsername();

		param.setId("welcome");
		param.setEditUserId(strId);
		
		manageDAO.updateInfomation(param);
	}

	
	@Override
	@Transactional (readOnly=true)
	public Information getHistory() {
		Information param = new Information();
		param.setId("history");
		
		return manageDAO.selectInfomation(param);
	}
	
	
	@Override
	@Transactional
	public void editHistory(Information param) {
		String strId;
		Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		strId = ((UserDetails)principal).getUsername();

		param.setId("history");
		param.setEditUserId(strId);
		
		manageDAO.updateInfomation(param);
	}

	
	@Override
	@Transactional (readOnly=true)
	public Information getRegulation() {
		Information param = new Information();
		param.setId("regulation");
		
		return manageDAO.selectInfomation(param);
	}
	
	
	@Override
	@Transactional
	public void editRegulation(Information param) {
		String strId;
		Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		strId = ((UserDetails)principal).getUsername();

		param.setId("regulation");
		param.setEditUserId(strId);
		
		manageDAO.updateInfomation(param);
	}




}
